'''
Human Alliance WCS:Python Race Coded By: J3ff Hoogland
'''
import wcs, es, random, playerlib, gamethread
from wcs import wcs
#Our Race's Name - This is not needed I just feel it makes things look cleaner
RaceName = 'Human Alliance'
wcs.Race(RaceName).registerSkill('Invisibility', 6, 2, 'Makes you partially invisible.')
wcs.Race(RaceName).registerSkill('Devotion Aura', 4, 1, 'Gives you additional health each round.')
wcs.Race(RaceName).registerSkill('Bash', 4, 3, 'Have a chance to stun the person you hit with an attack.')
wcs.Race(RaceName).registerUltimate('Avatar', 8, 3, 4, 'Hold down your ultimate key to get stronger for a short time.')

def player_spawn(event_var):
	userid = int(event_var['userid'])
	invisi(userid)
	devo = wcs.GetLevel(userid, RaceName, 'Devotion Aura')*15
	if devo:
		wcs.Command(userid).HealthAdd(devo)
		es.tell(userid, '#multi', '#lightgreenDevotion Aura #default- #greenYou have %s bonus health.'%(devo))
	wcs.Command(userid).UpdateDict('avatar', 0)
def item_pickup(event_var):
	userid = int(event_var['userid'])
	ava = wcs.Command(userid).ReturnDict('avatar')
	if not ava:
		invisi(userid)
def player_hurt(event_var):
	userid = int(event_var['userid'])
	attacker = int(event_var['attacker'])
	damage = int(event_var['dmg_health'])
	bash = wcs.GetLevel(attacker, RaceName, 'Bash')*8
	if bash:
		if bash >= random.randint(1,100):
			effectlib.drawLine(es.getplayerlocation(userid), es.getplayerlocation(attacker), red=0, green=0)
			wcs.Command(userid).Freeze(4)
			es.tell(attacker, '#multi', '#lightgreenBash #default- #greenYou have stunned %s.'%(event_var['es_username']))
	ava = wcs.GetLevel(attacker, RaceName, 'Avatar')
	if ava:
		state = wcs.Command(attacker).ReturnDict('avatar')
		if state:
			wcs.Command(userid).damage(damage*.3,32,attacker)
def player_ultimate_on(event_var):
	userid = int(event_var['userid'])
	ava = wcs.GetLevel(userid, RaceName, 'Avatar')*4
	if ava:
		wcs.Command(userid).UpdateDict('avatar', 1)
		wcs.Command(userid).HealthAdd(100)
		wcs.Command(userid).Color(blue=255)
		gamethread.delayed(ava, avaoff, userid)
def player_ultimate_off(event_var):
	userid = int(event_var['userid'])
	ava = wcs.GetLevel(userid, RaceName, 'Avatar')
	if ava:
		avaoff(userid)
def invisi(userid):
	invis = wcs.GetLevel(userid, RaceName, 'Invisibility')
	if invis:
		wcs.Command(userid).Color(alpha=invis*20+90)
def avaoff(userid):
	state = wcs.Command(userid).ReturnDict('avatar')
	if state:
		wcs.Command(userid).UpdateDict('avatar', 0)
		invisi(userid)
		wcs.Command(userid).SetCoolDown('Avatar', 8)
		if playerlib.getPlayer(userid).get('health') >= 101:
			wcs.Command(userid).HealthAdd(-100)
		else:
			wcs.Command(userid).Damage(100)